#pragma once

#include <d3d11.h>
#include <DirectXMath.h>
#include "ShaderGroup.h"
#include "Texture.h"
#include <vector>
using namespace DirectX;




struct VERTEX
{
	XMFLOAT3 pos;
	XMFLOAT3 normal;
	XMFLOAT2 uv;
	XMFLOAT4 _color;

};

struct SIMPLE_VERTEX
{
	XMFLOAT4 pos;
	XMFLOAT4 color;
};
struct INSTANCE_STRUCT
{
	XMFLOAT4X4 instMatrix;
};

class D3DMesh
{
public:
	D3DMesh();
	~D3DMesh();

	HRESULT Initizalize(ID3D11Device* device, const char* objPath, const char* texturePath, bool isSkyBox = 0);
	
	HRESULT CreateFromVectors(ID3D11Device* device, VERTEX* verts, unsigned int* indicies, unsigned int numVerts, unsigned int numInd, XMFLOAT4 color, const char* textureFile = NULL);


	
	
	void Render(ID3D11DeviceContext* pContext, ShaderGroup* shader, VS_CONSTANT_BUFFER* vsConstBufferInfo, DIR_LIGHT_BUFFER* dlbufferInfo, POINT_LIGHT_BUFFER* plbufferInfo, SPOT_LIGHT_BUFFER* slbufferInfo, float dt);
	void RenderIndexed(ID3D11DeviceContext* pContext, ShaderGroup* shader, VS_CONSTANT_BUFFER* vsConstBufferInfo, DIR_LIGHT_BUFFER* dlbufferInfo, POINT_LIGHT_BUFFER* plbufferInfo, SPOT_LIGHT_BUFFER* slbufferInfo, float dt);
	//void RenderIndexedInstanced(ID3D11DeviceContext* pContext, ShaderGroup* shader, ID3D11Buffer* shader, VS_CONSTANT_BUFFER* vsConstBufferInfo, PS_CONSTANT_BUFFER* psConstBufferInfo, float dt, unsigned int numberInstances);

	void SetWorldMatrix(XMFLOAT4X4 newMatrix);
	void ShutDown();


private:
	
	HRESULT LoadMeshFromObjFile(ID3D11Device* device, const char* path, bool isSkyBox);
	HRESULT LoadTexture(ID3D11Device* device, const char* path);
	XMFLOAT4X4 matrix;
	ID3D11Buffer  *m_pVertexBuffer, *m_pIndexBuffer;
	Texture m_pTexture;

	unsigned int m_nNumVerts, m_nNumIndicies;

	void DrawIndexedMesh();
	void DrawMesh();
};

